package com.fonts;

import com.exception.FontRegistoryException;

import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

public abstract class AbstractFont implements Font{

    private static final Map<String, Font> INNER_FONT = new ConcurrentHashMap<>();

    public static Font chooseFont(String fontName) {
        return INNER_FONT.get(fontName);
    }

    public static void register(String fontName, Font registerFont) {
        Font font = chooseFont(fontName);
        if (Objects.nonNull(font)) {
            throw new FontRegistoryException(String.format("bean %s register", font.getClass().getName()));
        }
        INNER_FONT.put(fontName, registerFont);
    }
}
